package view;

import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

/**
 * The Class ViewPhotoWithLayerGUI.
 * @author Dmitry
 */
public class ViewPhotoWithLayerGUI extends AbstractGUI {
	
	/** The sample panel. */
	private JPanel samplePanel = null;
	
	/** The sample. */
	private BufferedImage sample = null;
	
	/** The label. */
	private JLabel label = null;
	
	/** The icon. */
	private ImageIcon icon = null;
	
	/**
	 * Instantiates a new view photo with layer gui.
	 */
	public ViewPhotoWithLayerGUI() {
		getContentPane().setLayout(null);
		getContentPane().add(getSamplePanel());
		getContentPane().add(getBackButton());
		this.setTitle("Photo Layer");
		this.setBounds(200, 200, 938, 517);
		this.setVisible(true);
	}
	
	/**
	 * This method both creates and returns a photo layer panel which contains the label which holds the 
	 * BufferedImage image.
	 *
	 * @return the sample panel
	 */
	private JPanel getSamplePanel(){
		if(samplePanel == null){
			samplePanel = new JPanel();
			samplePanel.setBorder(new TitledBorder(null, "Photo Layer", TitledBorder.CENTER, TitledBorder.BOTTOM, null, null));
			samplePanel.setBounds(10, 11, 902, 378);
			samplePanel.setLayout(null);
			samplePanel.add(getLabel());
		}
		return samplePanel;
	}
	
	/**
	 * This method both creates and returns a BackButton instance.
	 *
	 * @return the back button
	 */
	private JButton getBackButton(){
		if(backButton == null){
			backButton = new JButton("Back");
			backButton.setBounds(418, 419, 89, 23);
		}
		return backButton;
	}
	
	/**
	 * This method both creates and returns a label instance which holds the displayed image.
	 * @return JLabel instance.
	 */
	private JLabel getLabel(){
		if(label == null){
			label = new JLabel("");
			label.setBounds(10, 11, 882, 345);
		}
		return label;
	}
	
	/**
	 * This method both creates and returns an ImageIcon instance.
	 * @return ImageIcon instance.
	 */
	private ImageIcon getIcon(){
		if(icon == null){
			icon = new ImageIcon();
		}
		return icon;
	}
	
	/**
	 * This method sets a new BufferedImage instance.
	 * @param sample - BufferedImage typed image.
	 */
	private void setImage(BufferedImage sample){
		getIcon().setImage(sample);
	}
	
	/**
	 * This method shows the image.
	 *
	 * @param sample the sample
	 */
	public void displayImage(BufferedImage sample){
		setImage(sample);
		getLabel().setIcon(getIcon());
		
	}
	
	/**
	 * This method returns PhotoLayerPanel's width.
	 *
	 * @return the photo with layer panel width
	 */
	public int getPhotoWithLayerPanelWidth(){
		return getLabel().getWidth();
	}
	
	/**
	 * This method returns PhotoLayerPanel's height.
	 *
	 * @return the photo with layer panel height
	 */
	public int getPhotoWithLayerPanelHeight(){
		return getLabel().getHeight();
	}
	
	/**
	 * This method displays warning messages.
	 * @param msg contains warning message.
	 */
	public void displayWrnMessage(String msg){
		JOptionPane.showInternalMessageDialog(null, msg,
				"information", JOptionPane.INFORMATION_MESSAGE);
	}
}
